﻿#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#include<windows.h>
#include<locale.h>
#include<time.h>
#define POS_X 24
#define POS_Y 5
#define WALL L'■' //□⨌
#define BODY L'●' //◯↑↓←→
#define FOOD L'￥' //▦∰∭$¥₩₯ℳ⿰௹₧
#define KEY_PRESS(vk) (GetAsyncKeyState(vk)&0x1?1:0)

enum GAME_STATUES {
	OK = 1,
	ESC,
	KILL_BY_WALL,
	KILL_BY_SELF
};

enum DIRECTION {
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};

typedef struct SnakeNode
{
	int x;
	int y;
	struct SnakeNode* next;
}SnakeNode, * pSnakeNode;

typedef struct Snake
{
	pSnakeNode pSnake;//指向蛇头节点的指针
	pSnakeNode pFood;//指向食物的食物指针
	int Score;//当前分数
	int FoodWeight;//食物比重
	int SleepTime;//休眠时间
	enum GAME_STATUES status;//游戏当前状态
	enum DIRECTION dir;//蛇当前方向
}Snake, * pSnake;

//游戏开始的维护
void GameStart(pSnake ps);

//绘制地图
void CreateMap();

//初始化蛇
void InitSnake(pSnake ps);

//初始化食物
void CreateFood(pSnake ps);

//设置光标位置
void SetPos(int x, int y);

//游戏运行维护函数
void GameRun(pSnake ps);

//游戏结束善后
void GameEnd(pSnake ps);

//蛇移动
void SnakeMove(pSnake ps);